#ifndef _GL_BUFFER_H_
#define _GL_BUFFER_H_

#include "../glew/glew.h"

#include "glSubresourceData.h"

typedef enum GL_BIND_FLAG
{
  GL_BIND_VERTEX_BUFFER   = GL_ARRAY_BUFFER,
  GL_BIND_INDEX_BUFFER    = GL_ELEMENT_ARRAY_BUFFER,
  GL_BIND_CONSTANT_BUFFER = GL_UNIFORM_BUFFER_EXT,
  GL_BIND_SHADER_RESOURCE = GL_TEXTURE_BUFFER_EXT,
  GL_BIND_STREAM_OUTPUT   = GL_TRANSFORM_FEEDBACK_BUFFER_NV,
  GL_BIND_RENDER_TARGET   = GL_PIXEL_PACK_BUFFER,
  //GL_BIND_DEPTH_STENCIL   = 0x0000,
} GL_BIND_FLAG;

typedef enum GL_USAGE
{
	//////////////////////////////////////////////////////////////////////////
	/// In OGL the buffers are difficult to understand
	/// Frequancy of access (modification / usage)
	///						Modified			Used
	/// STREAM				once			 few
	/// STATIC				once			many
	/// DYNAMIC				many			many
	/// Nature of usage
	///						CPU			GPU		
	/// DRAW				W				R
	/// READ				R				W
	/// COPY							 RW

  GL_USAGE_STREAM_DRAW  = GL_STREAM_DRAW, 
  GL_USAGE_STREAM_READ  = GL_STREAM_READ,
  GL_USAGE_STREAM_COPY  = GL_STREAM_COPY,
  GL_USAGE_STATIC_DRAW  = GL_STATIC_DRAW,
  GL_USAGE_STATIC_READ  = GL_STATIC_READ,
  GL_USAGE_STATIC_COPY  = GL_STATIC_COPY,
  GL_USAGE_DYNAMIC_DRAW = GL_DYNAMIC_DRAW,
  GL_USAGE_DYNAMIC_READ = GL_DYNAMIC_READ,
  GL_USAGE_DYNAMIC_COPY = GL_DYNAMIC_COPY,

	//////////////////////////////////////////////////////////////////////////
	/// D3D10 uses a simpler notation for resources
	/// Usage			Default		Dynamic		Immutable		Staging 
	/// GPU-Read			yes				yes					yes				yes
	/// GPU-Write			yes															yes 
	/// CPU-Read																			yes
	/// CPU-Write								yes										yes 
	//////////////////////////////////////////////////////////////////////////

	GL_USAGE_DEFAULT		= GL_DYNAMIC_COPY,
	GL_USAGE_IMMUTABLE	= GL_STATIC_DRAW,
	GL_USAGE_DYNAMIC		= GL_DYNAMIC_DRAW,
	GL_USAGE_STAGING		= GL_DYNAMIC_COPY,

} GL_USAGE;

typedef struct GL_BUFFER_DESC 
{
  unsigned int ByteWidth;
  GLenum Usage;
  unsigned int BindFlags;
  unsigned int CPUAccessFlags;
  unsigned int MiscFlags;
  GL_BUFFER_DESC()
  {
    ByteWidth = 0;
    Usage = GL_USAGE_DYNAMIC_DRAW;
    BindFlags = GL_BIND_VERTEX_BUFFER;
    CPUAccessFlags = 0;
    MiscFlags = 0;
  }
} GL_BUFFER_DESC;

bool glCreateBuffer(GL_BUFFER_DESC *pDesc,
                    GL_SUBRESOURCE_DATA *pInitData,
                    unsigned int *pBuffer);

bool glDeleteBuffer(unsigned int *pBuffer);

#endif
